<%@ page contentType="text/html;charset=UTF-8" language="java" %>

<!DOCTYPE html>
<html>
<head>
    <jsp:include page="head.jsp"></jsp:include>
    <link rel="stylesheet" href="<%= request.getAttribute("StaticHost") %>/css/square/blue.css">

    <link rel="stylesheet" href="http://cdn.bootcss.com/bootstrap/3.3.7/css/bootstrap.min.css">
    <script src="http://cdn.bootcss.com/jquery/2.1.1/jquery.min.js"></script>
    <script src="http://cdn.bootcss.com/bootstrap/3.3.7/js/bootstrap.min.js"></script>
</head>
<body class="hold-transition login-page">
<div style="position: fixed;height: 100%;width:100%;top:0;left:0;z-index: 9;">
    <div id="myCarousel" class="carousel slide" >
        <!-- 轮播（Carousel）指标 -->
        <%--<ol class="carousel-indicators">
            <li data-target="#myCarousel" data-slide-to="0" class="active"></li>
            <li data-target="#myCarousel" data-slide-to="1"></li>
            <li data-target="#myCarousel" data-slide-to="2"></li>
        </ol>--%>
        <!-- 轮播（Carousel）项目 -->
        <%--<div class="carousel-inner" style="position: fixed;height:100%;width:100%;bottom:0;">
            <div class="item active" style="height: 100%;">
                <img style="width: 100%;height: 100%;" src="<%= request.getAttribute("StaticHost") %>/img/login001.jpg" alt="First slide">
            </div>
            <div class="item" style="height: 100%;">
                <img style="width: 100%;height: 100%" src="<%= request.getAttribute("StaticHost") %>/img/login002.jpg" alt="Second slide">
            </div>
            <div class="item" style="height: 100%;">
                <img style="width: 100%;height: 100%" src="<%= request.getAttribute("StaticHost") %>/img/login003.jpg" alt="Third slide">
            </div>
        </div>--%>
        <!-- 轮播（Carousel）导航 -->
        <%--<a class="left carousel-control" href="#myCarousel" role="button" data-slide="prev">
            <span class="glyphicon glyphicon-chevron-left" aria-hidden="true"></span>
            <span class="sr-only">Previous</span>
        </a>
        <a class="right carousel-control" href="#myCarousel" role="button" data-slide="next">
            <span class="glyphicon glyphicon-chevron-right" aria-hidden="true"></span>
            <span class="sr-only">Next</span>
        </a>--%>
    </div>
</div>
<script>
     var timer = setInterval("$('#myCarousel').carousel('next');",3000);
</script>
<div style="position: fixed;z-index: 10;width:100%;height: 100%;">
    <div class="login-box">
        <div class="login-logo">
            <a href="${pageContext.request.contextPath}"><b>商户服务平台</b></a>
        </div>
        <!-- /.login-logo -->
        <div class="login-box-body" style="background: #fff;opacity: 0.6;border-radius: 5px;box-shadow:10px 10px 5px #888888; ">
            <p class="login-box-msg">Sign in to start your session</p>

            <form>
                <div class="form-group has-feedback">
                    <input type="text" class="form-control" placeholder="用户名" name="username" id="username">
                    <span class="glyphicon glyphicon-envelope form-control-feedback"></span>
                </div>
                <div class="form-group has-feedback">
                    <input type="password" class="form-control" placeholder="密码" name="password" id="password">
                    <span class="glyphicon glyphicon-lock form-control-feedback"></span>
                </div>
                <div class="row">
                    <div class="col-xs-8">
                        <div class="checkbox icheck">
                            <label>
                                <input type="checkbox"> Remember Me
                            </label>
                        </div>
                    </div>
                    <!-- /.col -->
                    <div class="col-xs-4">
                        <button type="button" id="btnPassLogin" class="btn btn-primary btn-block btn-flat">登 录</button>
                    </div>
                    <input type="hidden" value="aaaa" class="am-form-field" name="validCode" id="validCode">
                    <!-- /.col -->
                </div>
            </form>
        </div>
        <!-- /.login-box-body -->
    </div>
</div>

<script src="http://amazeui.org/js/jquery.min.js"></script>
<script src="<%= request.getAttribute("StaticHost") %>/js/bootstrap.min.js"></script>
<script src="<%= request.getAttribute("StaticHost") %>/js/icheck.min.js"></script>
<script type="application/javascript">
    $(function () {
        $('input').iCheck({
            checkboxClass: 'icheckbox_square-blue',
            radioClass: 'iradio_square-blue',
            increaseArea: '20%' // optional
        });

    });
    $(document).ready(function () {
        $("#imgValidCode").click(function () {
            reloadValidCode();
        });
        $("#password").on("keyup", function (event) {
            if (event.keyCode == 13) {
                //alert("a");
                $('#btnPassLogin').trigger("click");
            }
        });

        function reloadValidCode() {
            var d = new Date();
            $('#imgValidCode').attr("src", "${pageContext.request.contextPath}/login/validcode?w=180&h=36&" + d.getTime())
            $('#validCode').val('')
        }

        $('#btnPassLogin').on('click', function () {
            //$(this).attr("dis")
            var username = $('#username');
            var password = $('#password');
            var validCode = $('#validCode');

            if (username.val() == '') {
                alert('请输入用户名');
                return false;
            }

            if (password.val() == '') {
                alert('请输入密码');
                return false;
            }

//            if (validCode.val() == '') {
//                alert('请输入验证码')
//            }

            $.ajax({
                type: 'POST',
                url: "/login/pass",
                data: {password: password.val(), username: username.val(), validCode: validCode.val()},
                success: function (data) {
                    if (data) {
                        if (data.code == 200) {
                            var url = data.data;
                            if (url) {
                                location.href = url;
                            }
                            else {
                                location.href = '${pageContext.request.contextPath}/index';
                            }
                            return false;
                        }
                        else {
                            alert(data.msg);
                            if(data.code==440){
                                location.href = '${pageContext.request.contextPath}/login/sign?uid='+data.data;
                            }

                        }
                        //reloadValidCode();
                    } else {
                        alert('服务器异常，请稍后再试！');
                        //reloadValidCode();
                    }
                },
                error: function () {
                    alert('服务器异常，请稍后再试！');
                }
            })

        });
    })
</script>
</body>
</html>

